﻿using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.Tools.CodeRunner.Tasks.UnitTest
{
    /// <summary>
    /// 
    /// </summary>
    public sealed class TraceLoggingBuildEngine : IBuildEngine, IEventSource
    {
        #region Construction
        public TraceLoggingBuildEngine()
        {
        }

        #endregion

        #region IBuildEngine Members
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        public void LogErrorEvent(BuildErrorEventArgs e)
        {
            if (ErrorRaised != null)
                ErrorRaised(this, new BuildErrorEventArgs(
                    e.Subcategory, e.Code, e.File, e.LineNumber, e.ColumnNumber, e.EndColumnNumber, e.EndColumnNumber, e.Message, e.HelpKeyword, e.SenderName));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        public void LogWarningEvent(BuildWarningEventArgs e)
        {
            if (WarningRaised != null)
                WarningRaised(this, new BuildWarningEventArgs(
                    e.Subcategory, e.Code, e.File, e.LineNumber, e.ColumnNumber, e.EndColumnNumber, e.EndColumnNumber, e.Message, e.HelpKeyword, e.SenderName));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        public void LogMessageEvent(BuildMessageEventArgs e)
        {
            if (MessageRaised != null)
                MessageRaised(this, new BuildMessageEventArgs(e.Message, e.HelpKeyword, e.SenderName, e.Importance));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        public void LogCustomEvent(CustomBuildEventArgs e)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        public bool ContinueOnError
        {
            get { return false; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string ProjectFileOfTaskNode
        {
            get { return String.Empty; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int LineNumberOfTaskNode
        {
            get { return 0; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int ColumnNumberOfTaskNode
        {
            get { return 0; }
        }

        /// <summary>
        /// The callback to build another project file.
        /// </summary>
        /// <param name="projectFileName"></param>
        /// <param name="targetNames"></param>
        /// <param name="globalProperties"></param>
        /// <param name="targetOutputs"></param>
        /// <returns></returns>
        public bool BuildProjectFile(
            string projectFileName,
            string[] targetNames,
            IDictionary globalProperties,
            IDictionary targetOutputs)
        {
            return false;
        }

        #endregion    
        
        #region IEventSource Members
    
        // Disable CS0067 for unused members
        #pragma warning disable 67

        public event AnyEventHandler AnyEventRaised;

        public event BuildFinishedEventHandler BuildFinished;

        public event BuildStartedEventHandler BuildStarted;

        public event CustomBuildEventHandler CustomEventRaised;

        public event BuildErrorEventHandler ErrorRaised;

        public event BuildMessageEventHandler MessageRaised;

        public event ProjectFinishedEventHandler ProjectFinished;

        public event ProjectStartedEventHandler ProjectStarted;

        public event BuildStatusEventHandler StatusEventRaised;

        public event TargetFinishedEventHandler TargetFinished;

        public event TargetStartedEventHandler TargetStarted;

        public event TaskFinishedEventHandler TaskFinished;

        public event TaskStartedEventHandler TaskStarted;

        public event BuildWarningEventHandler WarningRaised;

        #endregion
    }
}
